//
//  DinnerViewController.m
//  Simple Life
//
//  Created by lanou3g on 15/11/12.
//  Copyright © 2015年 wyt. All rights reserved.
//

#import "DinnerViewController.h"
#import "DinnerCollectionViewCell.h"
#import "DinnerModel.h"
#import "DinnerDataHandel.h"
#import "UIImageView+WebCache.h"


@interface DinnerViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UIScrollViewDelegate>



@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UILabel *LineLable;

@end

@implementation DinnerViewController
- (IBAction)meas:(UIButton *)sender {
    
    self.scrollView.contentOffset = CGPointMake(self.view.frame.size.width *0, 0);
  //  self.LineLable.frame = CGRectMake(self.view.frame.size.width /2 *0, self.LineLable.frame.origin.y, self.LineLable.frame.size.width, self.LineLable.frame.size.height);
}

- (IBAction)sweat:(UIButton *)sender {
    self.scrollView.contentOffset = CGPointMake(self.view.frame.size.width *1, 0);
 //   self.LineLable.frame = CGRectMake(self.view.frame.size.width /2 *1, self.LineLable.frame.origin.y, self.LineLable.frame.size.width, self.LineLable.frame.size.height);
}

- (void)viewDidLoad {
    [super viewDidLoad];

#pragma mark--两个页面
    
    
//    self.scrollView.delegate = self;
//    [self.view addSubview:self.scrollView];
//    self.scrollView.pagingEnabled = YES;
//    self.scrollView.bounces = NO;
    
       
    
    
    
    
    
    
#pragma mark--第一个页面的数据
    
    [DinnerDataHandel defauDinnerDataHandel];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self.collectionView registerClass:[DinnerCollectionViewCell class] forCellWithReuseIdentifier:@"myCell"];

    self.collectionView.backgroundColor = [UIColor whiteColor];
   
    
    
    //当数据处理完毕，回到主线程发送通知
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishLoadData) name:@"finishData" object:nil];
    
}

- (void)finishLoadData
{
    [self.collectionView reloadData];
}
-(void)segAction:(UISegmentedControl *)sender
{
    
}

#pragma mark -- UICollectionDelegateFlowLayoutAndDataSource

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return [[DinnerDataHandel defauDinnerDataHandel] modelCount];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DinnerCollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];
    //[cell.pictureImageView setImage:[UIImage imageNamed:@"zxbd_ht@2x.png"]];
    //cell.dinnerName.text = @"asd";

    DinnerModel *m = [[DinnerDataHandel defauDinnerDataHandel] modelWithIndex:indexPath.row];
    
    
    cell.dinnerName.text=[NSString stringWithFormat:@"%@",m.RecipeName];
    
    
    //NSLog(@"============%@",cell.dinnerName.text);
    
    
    NSURL *imageUrl = [NSURL URLWithString:m.ThumbnailUrl];
    [cell.pictureImageView sd_setImageWithURL:imageUrl completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    
    return cell;
}

#pragma mark--选中某个菜品
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
